/**
 * @Date 2019-12-09 16:08:30
 * @Remark
 */

import { InternalRuleItem, Rules, Value } from "async-validator";

// 验证身份证
export function verifyIdentityNo(rule: Rules, value: string) {
  const reg = /(^\d{8}(0\d|10|11|12)([0-2]\d|30|31)\d{3}$)|(^\d{6}(18|19|20)\d{2}(0\d|10|11|12)([0-2]\d|30|31)\d{3}(\d|X|x)$)/;
  const result = reg.test(value);
  return result;
}

// 验证内地手机号
export function isMobile(value: string) {
  const reg = /^(?:(?:\+|00)86)?1(?:(?:3[\d])|(?:4[5-7|9])|(?:5[0-3|5-9])|(?:6[5-7])|(?:7[0-8])|(?:8[\d])|(?:9[1|8|9]))\d{8}$/;
  const result = reg.test(value);
  return result;
}

export function verifyMobile(rule: InternalRuleItem, value: Value) {
  if (value && value !== "") {
    return isMobile(value);
  }
  return true;
}
